<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-waiting-current-waiting" :style="getStyle('area')">
      <div class="waiting-inside" v-for="(item, index) in doctorPatientList" :key="item['workerId']">
        <div class="dept-area">
          <ScrollX>{{ item.deptName || ' ' }}</ScrollX>
        </div>
        <div class="patient-area">
          <div class="current-area">
            <div class="title" :style="getStyle('currentTitle')">
              <ScrollX>{{optionsInfo['currentPaperwork']}}</ScrollX>
            </div>
            <div class="content">
              <p v-for="(itemInfo,index) in treatingPatientInfo(item)" :key="`${itemInfo.orderNo}-${index}`" :style="getStyle('currentTitle')">
                {{ itemInfo.orderNo }}
                {{ itemInfo.patientName }}
              </p>
            </div>
          </div>
          <div class="waiting-area">
            <div class="title" :style="getStyle('waitingTitle')">
              <ScrollX>{{optionsInfo['waitingPaperwork']}}</ScrollX>
            </div>
            <div class="content" v-if="true">
              <div class="content-inside"
                   v-for="(itemInfo, key) in waitingChunkInfos(item.waitPatientList)"
                   :key="key"
                   :class="{'even':!!key%2}"
              >
                <div class="patient-item" v-for="(itemInfo2, itemInfoKey2) in itemInfo" :key="`${itemInfo2.queuingId}-${itemInfoKey2}`" :style="getStyle('waitingTitle')">
                  <div class="patient-item-inside">
                    {{ itemInfo2.orderNo }}{{ itemInfo2.patientName }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import {pxToVw} from '@/utils/common';
import emitter from "@/utils/designer/emitter";
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue'
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";
let buildParent = buildParentApi();
export default {
  name: "scene-waiting-double-dept-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX,
  },

  props: {
    widget: Object,
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    devType: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },

    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
  },

  data() {
    return {
      week: '',
      mockOpen: false,
      waitPatientList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            return Obj;
          case "currentTitle":
            Reflect.set(Obj, 'fontSize', pxToVw((info.currentFontSize) || 50));
            return Obj;
          case "waitingTitle":
            Reflect.set(Obj, 'fontSize', pxToVw((info.waitingFontSize) || 50));
            return Obj;
        }
      }
    },

    //  队列-患者-数据
    doctorPatientList() {
      let data;
      let devType = (this.devType);
      let WaitingPatientList = this.$store.getters['getWaitingPatientInfo'];
      if (devType) {
        data = (WaitingPatientList.apiData)
      } else {
        data = (WaitingPatientList.mockData)
      }
      if (data && !!(data.length)) {
        if((data.length)>=2){
          return data.slice(0, 2);
        }else {
          let arr = (new Array(2 - data?.length).fill({waitPatientList:[]}));
          return [...data, ...arr];
        }
      } else {
        return [{waitPatientList:[]},{waitPatientList:[]}]
      }
    },

    // 当前就诊患者
    treatingPatientInfo() {
      return function (info) {
        if (!!(info.treatingPatient) && !!(info.treatingPatient.length)) {
          return (info.treatingPatient).slice(0, 1)
        } else {
          return []
        }
      }
    },

    // 切割候诊患者
    waitingChunkInfos() {
      return function (info) {
        if (info.length > 4) {
          let flattenArr2 = info.slice(0, 4);
          return this.$lodash.chunk(flattenArr2, 2)
        } else {
          let arr = (new Array(4 - info.length).fill({}));
          let flattenArr2 = [...info, ...arr];
          return this.$lodash.chunk(flattenArr2, 2)
        }
      }
    },
  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "patientListInfo":
          let patientList = this.$lodash.cloneDeep(data);
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign:'模板-患者信息',key:key,data:data}));
          this.$store.dispatch('setWaitingPatientInfo', patientList)
          break
      }
    }
  },

  watch: {
    field: {
      handler: function (val) {
        this.optionsInfo = (val.options[val.options.config]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },
};
</script>

<style lang="scss" scoped>
.scene-waiting-current-waiting {
  padding: 28px 30px 10px 30px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: nowrap;
  flex-direction: row;
  color: #333;
  height: auto;
  font-size: 50px;
  overflow: hidden;
  background: #E5EAEF;

  .waiting-inside {
    min-width: calc(100% / 2 - 15px);

    &:first-child {
      box-sizing: border-box;
      margin-right: 15px;
    }

    &:last-child {
      box-sizing: border-box;
      margin-left: 15px;
    }
  }

  .dept-area {
    font-size: 76px;
    color: #FFFFFF;
    width: 100%;
    text-align: center;
    background: #0059B3;
    padding: 0 20px;
    height: 186px;
    line-height: 186px;
    overflow: hidden;
    border-radius: 32px 32px 0 0;
    @include singleEllipsis(100%)
  }

  .patient-area {
    box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
    inset 5px 5px 10px rgba(255, 255, 255, 0.75),
    inset -1px -1px 10px rgba(0, 0, 0, 0.2);

    .current-area {
      margin-top: 16px;
      display: flex;
      align-items: center;
      align-self: center;
      border-radius: 12px;
      height: 160px;
      overflow: hidden;
      flex-direction: row;
      background: rgba(0, 89, 179, 1);

      .title {
        color: white;
        font-size: 40px;
        height: 100%;
        box-sizing: border-box;
        width: 260px;
        padding: 0 20px;
        background: rgba(0, 71, 143, 1);
        display: flex;
        justify-content: center;
        align-items: center;
        align-self: center;
        .scrollText{
          width: 100%;
        }
      }

      .content {
        color: white;
        display: flex;
        flex: 1;
        flex-direction: row;
        align-items: center;
        align-self: center;
        width: calc(100% - 270px);

        p {
          flex-basis: calc(100% / 1);
          font-size: 44px;
          color: white;
          text-align: center;
          padding: 0 20px;
          box-sizing: border-box;
          @include singleEllipsis(100%)
        }
      }
    }

    .waiting-area {
      display: flex;
      margin-top: 14px;
      flex-direction: column;
      border-radius: 0 0 24px 24px;
      overflow: hidden;

      .title {
        background: linear-gradient(rgba(244, 244, 244, 1) 0%, rgba(240, 240, 240, 1) 100%);
        text-align: center;
        font-size: 50px;
        height: 120px;
        width: 100%;
        color: #0059B3;
        border-bottom: 2px solid #DDDDDD;
        @include fontWeight();
        display: flex;
        padding: 0 20px;
        align-self: center;
        align-items: center;
        justify-content: center;
        .scrollText{
          width: 100%;
        }
      }

      .content {
        background: white;
        display: flex;
        flex-wrap: wrap;

        .content-inside {
          width: 100%;
          display: flex;
          padding: 8px 0;
          flex-wrap: wrap;

          .patient-item {
            flex-basis: calc(100% / 2);
            font-weight: 400;
            text-align: center;
            height: 120px;
            font-size: 54px;
            display: flex;
            align-items: center;
            align-self: center;
            justify-content: center;
            color: #333333;
            overflow: hidden;
            .patient-item-inside{
              padding: 0 24px;
              @include singleEllipsis(100%)
            }
          }
        }
      }

      .even {
        background: rgba(244, 244, 244, 1);
      }
    }
  }


}
</style>
